package project.controllers;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class ExceptionController {
    //value值为错误的类名，如：NullPointerException.class
    @ExceptionHandler(value = {ArithmeticException.class, NullPointerException.class})
    public String testExceptionHandler2(Exception ex, Model model) {
        model.addAttribute("ex", ex);
        // 需要在error page的元素中写上“th:text="${ex}"”属性
        return "error";
    }
}
